<template>
  <div class="list">
    <Header></Header>
    <div class="list-con">
      <div class="nav-aside">
        <ul>
          <li v-for="(category, index) in categoryList" :key="category.id">
            {{ category.name }}
          </li>
          <!-- <li class="active">新品</li> -->
        </ul>
      </div>
      <div class="nav-main">
        <img class="nav-ad" :src="adImgUrl" alt="" />
        <ul>
          <li v-for="(categoryItem, index) in categoryItemList" :key="index">
            <div v-for="item in categoryItem" :key="item.id">
              <div class="nav-title">{{item.name}}</div>
              <ul class="nav-list">
                <li v-for="list in item.list" :key="list.id">
                  <img :src="list.imgUrl" alt="" />
                  <span>{{list.name}}</span>
                </li>
              </ul>
            </div>
          </li>
        </ul>
      </div>
    </div>
    <Tabbar></Tabbar>
  </div>
</template>

<script>
import Header from "@/views/list/components/Header.vue";

export default {
  name: "List",
  data() {
    return {
      adImgUrl: "",
      dataInfo: [],
    };
  },
  components: {
    Header,
  },
  created() {
    this.getData();
  },
  computed: {
    categoryList() {
      return (
        this.dataInfo &&
        this.dataInfo.reduce((prev, cur) => {
          prev.push({
            id: cur.id,
            name: cur.name,
          });
          return prev;
        }, [])
      );
    },
    categoryItemList() {
      return (
        this.dataInfo &&
        this.dataInfo.reduce((prev, cur) => {
          prev.push(cur.data);
          return prev;
        }, [])
      );
    },
  },
  methods: {
    async getData() {
      let res = await this.$http.getCategoryList();
      console.log("getCategoryList", res);
      if (res.code === 200) {
        this.adImgUrl = res.data.adImgUrl;
        this.dataInfo = res.data.data;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.list {
  padding-bottom: 1.6rem;
  background-color: #fff;

  .list-con {
    display: flex;
    align-items: flex-start;

    .nav-aside {
      width: 25%;
      font-size: 0.4267rem;
      border-right: 1px solid #efefef;

      ul {
        li {
          text-align: center;
          padding: 0.1333rem 0;
          margin: 0.5333rem 0;
        }

        .active {
          color: #95111c;
          border-left: 3px solid #95111c;
        }
      }
    }

    .nav-main {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;

      .nav-ad {
        width: 92%;
        margin-top: 0.2667rem;
      }

      ul {
        padding: 0 0.1333rem;

        .nav-title {
          text-align: center;
          height: 1.3333rem;
          line-height: 1.3333rem;
          font-size: 0.5333rem;
          position: relative;
        }

        .nav-title::before,
        .nav-title::after {
          content: "";
          position: absolute;
          top: 50%;
          height: 0.0267rem;
          width: 0.5867rem;
          background-color: #b3abab;
        }

        .nav-title::before {
          left: 30%;
        }

        .nav-title::after {
          right: 30%;
        }

        .nav-list {
          display: flex;
          flex-wrap: wrap;
          // justify-content: space-between;

          li {
            display: flex;
            flex-direction: column;
            align-items: center;
            width: 33%;
            padding: 0.2667rem 0;

            img {
              width: 55%;
            }

            span {
              font-size: 0.3733rem;
            }
          }
        }
      }
    }
  }
}
</style>